<template>
  <div class="employees-container">
    <div class="app-container">
      <page-tools>
        <template #left>
          <span>总记录数: 16 条</span>
        </template>
        <template #right>
          <el-button type="warning" size="small">excel导入</el-button>
          <el-button type="danger" size="small">excel导出</el-button>
          <el-button type="primary" size="small">新增员工</el-button>
        </template>
      </page-tools>

      <el-card style="margin-top: 10px;">
        <el-table border :data="list">
          <el-table-column label="序号" />
          <el-table-column label="姓名" />
          <el-table-column label="工号" />
          <el-table-column label="聘用形式" />
          <el-table-column label="部门" />
          <el-table-column label="入职时间" />
          <el-table-column label="账户状态" />
          <el-table-column label="操作" width="280">
            <template>
              <el-button type="text" size="small">查看</el-button>
              <el-button type="text" size="small">分配角色</el-button>
              <el-button type="text" size="small">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <!-- 分页组件 -->
        <el-row type="flex" justify="center" align="middle" style="height: 60px">
          <el-pagination
            layout="total, sizes,prev, pager, next, jumper"
            :total="total"
            :page-size="size"
            :page-sizes="[2,5,10]"
            @current-change="hCurrentChange"
            @size-change="hSizeChange"
          />
        </el-row>
      </el-card>
      <el-dialog :visible.sync="showDialogRole">
        <assign-role />
      </el-dialog>
    </div>
  </div>
</template>
<script>
import { getEmployeeList } from '@/api/employee'
import AssignRole from './assignRole'
export default {
  components: {
  // 省略其他....
    AssignRole // 注册组件
  },
  data() {
    return {
      showDialogRole: false,
      list: [],
      page: 1,
      size: 5,
      total: 0
    }
  },
  created() {
    this.loadEmployeeList()
  },
  methods: {
    // 加载员工列表
    async loadEmployeeList() {
      try {
        const res = await getEmployeeList()
        console.log(res)
        this.list = res.data.rows
      } catch (err) {
        console.log(err)
        this.$message.error('加载员工数据失败')
      }
    },
    hCurrentChange(val) {
      this.page = val
      this.loadEmployee()
    },
    hSizeChange(val) {
      this.size = val
      this.loadEmployee()
    }
  }
}
</script>
